import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-04-05
 * Time: 17:13
 */
public class test30 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int year=sc.nextInt();
        int math= sc.nextInt();
        int day=sc.nextInt();
        boolean b = year % 400 == 0 || ((year % 4 == 0) && (year % 100 != 0));
        switch (math){
            case 1:{
                System.out.println(day);
                break;
            }
            case 2:{
                System.out.println(31+day);
            }
            case 3:{
if(b){
    System.out.println(31+29+day);
}else {
    System.out.println(31+28+day);
}
break;
            }
            case  4:{
                if(b){
                    System.out.println(31+29+31+day);
                }else {
                    System.out.println(31+28+31+day);
                }
                break;
            }
            case 5:{
                if(b){
                    System.out.println(31+29+31+30+day);
                }else {
                    System.out.println(31+28+31+30+day);
                }
                break;
            }
            case 6:{
                if(b){
                    System.out.println(31+29+31+30+31+day);
                }else {
                    System.out.println(31+28+31+30+31+day);
                }
                break;
            }
            case 7:{
                if(b){
                    System.out.println(31+29+31+30+31+30+day);
                }else {
                    System.out.println(31+28+31+30+31+30+day);
                }
                break;
            }
            case 8:{
                if(b){
                    System.out.println(31+29+31+30+31+30+31+day);
                }else {
                    System.out.println(31+28+31+30+31+30+31+day);
                }
                break;
            }
            case 9:{
                if(b){
                    System.out.println(31+29+31+30+31+30+31+31+day);
                }else {
                    System.out.println(31+28+31+30+31+30+31+31+day);
                }
                break;
            }
            case 10:{
                if(b){
                    System.out.println(31+29+31+30+31+30+31+31+30+day);
                }else {
                    System.out.println(31+28+31+30+31+30+31+31+30+day);
                }
                break;
            }
            case 11:{
                if(b){
                    System.out.println(31+29+31+30+31+30+31+31+30+31+day);
                }else {
                    System.out.println(31+28+31+30+31+30+31+31+30+31+day);
                }
                break;
            }
            case 12:{
                if(b){
                    System.out.println(31+29+31+30+31+30+31+31+30+31+30+day);
                }else {
                    System.out.println(31+28+31+30+31+30+31+31+30+31+30+day);
                }
                break;
            }
        }
    }
}
